package md.lanjing.com.module_mine.contact;

import android.content.Context;


import com.lxh.baselibray.mvp.BasePresent;
import com.lxh.baselibray.mvp.IBaseView;
import com.lxh.baselibray.net.NetCallBack;
import com.lxh.baselibray.net.ServiceGenerator;
import com.lxh.baselibray.util.Md5Utils;
import com.lxh.baselibray.util.ToastUtils;


import md.lanjing.com.module_mine.R;
import md.lanjing.com.module_mine.bean.ModifyDealPwdRequest;
import md.lanjing.com.module_mine.bean.RegisterSecurityCodeRequest;
import md.lanjing.com.module_mine.api.MineApiService;
import md.lanjing.com.module_mine.bean.ModifyDealPwdResponse;
import md.lanjing.com.module_mine.bean.ModifyDealPwdSecurityCodeResponse;
import retrofit2.Call;
import retrofit2.Response;

public class ModifyDealPwdContact {

    public static class ModifyDealPwdPresent extends BasePresent<IModifyDealPwdView> {
        public void getModifyDealPwdCode(final Context context, String phone){
            MineApiService service= ServiceGenerator.createService(MineApiService.class);
            RegisterSecurityCodeRequest request=new RegisterSecurityCodeRequest(phone,3);
            service.getModifyDealPwdSecurityCode(request).enqueue(new NetCallBack<ModifyDealPwdSecurityCodeResponse>() {
                @Override
                public void onSuccess(Call<ModifyDealPwdSecurityCodeResponse> call, Response<ModifyDealPwdSecurityCodeResponse> response) {
                    if (getView()!=null){
                        getView().getModifyDealPwdCodeData(response);
                    }
                }

                @Override
                public void onFailed() {
                    ToastUtils.showLongToast(context,context.getString(R.string.request_failed));
                }
            });

        }

        public void modifyDealPwd(final Context context, String code, String dealPwd, String phone){
            MineApiService service= ServiceGenerator.createService(MineApiService.class);
            ModifyDealPwdRequest request=new ModifyDealPwdRequest(Md5Utils.stringToMD5(dealPwd),code,phone);
            service.modifyDealPwd(request).enqueue(new NetCallBack<ModifyDealPwdResponse>() {
                @Override
                public void onSuccess(Call<ModifyDealPwdResponse> call, Response<ModifyDealPwdResponse> response) {
                    if (getView()!=null){
                        getView().getModifyDealPwdData(response);
                    }
                }

                @Override
                public void onFailed() {
                    ToastUtils.showLongToast(context,context.getString(R.string.request_failed));
                }
            });

        }
    }

    public interface IModifyDealPwdView extends IBaseView {
        void getModifyDealPwdCodeData(Response<ModifyDealPwdSecurityCodeResponse> response);
        void getModifyDealPwdData(Response<ModifyDealPwdResponse> response);
    }
}
